package com.li;

import com.sun.deploy.util.StringUtils;

/**
 * @author lirenchun
 */
public class PlateCheck {
    public static void main(String[] args) {
        System.out.println(checkPlate("川ZD75562"));
        System.out.println(checkPlate("粤AF66666"));
        System.out.println(checkPlate("粤A66666"));
        //System.out.println(checkPlatT("Z"));
    }

    /**
     * 中国车牌号校验
     *
     * @param plate
     * @return
     */
    public static boolean checkPlate(String plate) {
        boolean status = false;
        //常规车牌校验
        if (plate.length() == 7) {
            status = plate.matches("^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$");
        } else if (plate.length() == 8) {
            //新能源车牌校验
            status = plate.matches("^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[DF][A-Z0-9]{1}[0-9]{4}$");
            if(!status){
                status=plate.matches("^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[0-9]{5}[DF]$");
            }
        }
        return status;
    }

    public static boolean checkPlatT(String plate) {
        return plate.matches("^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Y]{1}[A-Z]{1}");
    }

}
